let api_url1 = 'http://localhost:3000'

function Http({ data = {}, url, type = 'get' }) { //这样用起来感觉像是用 $.ajax
    /*
       { data = {}, url, type = 'get' } = {
            url:'http://localhost:3000/api/banners'
        }
    */

    let{token}= JSON.parse(localStorage.getItem('userinfo'))
    return new Promise((resolve, reject) => {
        $.ajax({
            url:api_url1 + url,
            data,
            type,
           headers:{
                authorization:token
            },
            success(res) { //成功的回调
                resolve({ err: null, result: res })
            },
            error(err) {//失败的回调
                resolve({ err: err })
            }
        })
    })
}



function qsToJson(query) {
    let obj = {}
    let s1 = query.substring(1) //name=admin&keyword=%E5%95%86%E5%9F%8E
    let arr1 = s1.split('&') //[ 'name=admin','keyword=%E5%95%86%E5%9F%8E' ]
    // console.log(arr1)
    arr1.forEach(value => {
        let arr2 = value.split('=')
        obj[arr2[0]] = decodeURIComponent( arr2[1] )  
    })
    return obj
}